package cn.trigram.validation.annotation.validator;

import cn.trigram.lang.ConvertUtil;
import cn.trigram.validation.annotation.DateFormatCheck;
import java.util.Objects;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 字符日期时间格式校验器
 *
 * @version 1.0.0
 * @date 2022/08/04 09:11:06
 * @since 1.0.0
 */
public class DateFormatForIntegerValidator extends AbstractDateFormatValidator implements ConstraintValidator<DateFormatCheck, Integer> {

    @Override
    public void initialize(DateFormatCheck dateFormatCheck) {
        super.initialize(dateFormatCheck);
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (!dateFormatCheck.required() || Objects.isNull(value)) {
            return true;
        }
        final String str = ConvertUtil.toStr(value);
        return super.isValid(str, context);
    }
}